package com.lz.football.module.main.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.SharedEnterFrame;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.club.vo.BuffVo;
	import com.lz.football.module.base.IComponent;
	
	import common.item.IconItem;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	import lz.controls.ImageContain;

	/**
	 *buff显示 
	 * @author lake
	 */	
	public class BuffListPanel extends Sprite implements IComponent
	{
		/**
		 * icon item list
		 */		
		private var itemList :Array = [];
		
		public function BuffListPanel()
		{
			super();
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			showBuffInfo();
			addEvtListener();
			this.x += 10;
			this.y -= 0;
			//1分钟刷新
			SharedEnterFrame.instance.addFrameCall(refresh,.01);
		}
		/**
		 *刷新 
		 */		
		private function refresh():void
		{
			showBuffInfo();
		}
		/**
		 *显示buffer 
		 */		
		public function showBuffInfo():void
		{
			DisplayObjectUtil.removeAllChildren(this);
			var buffList :Array = AppData.getInstance().clubDatamanager.buffList;
			var buffId :int = 0;
			var buffDesc :String = "";
			var iconItem :IconItem;
			var i :int = 0;
			//buffList.push({buff:1,date:"2013-05-12 13:40:50"});
			//buffList.push({buff:1,date:"2013-05-12 13:40:50"});
			//buffList.push({buff:1,date:"2013-05-12 13:40:50"});
			var img :ImageContain;
			var j:int=0,k:int=0;;
			for each(var buffObj :BuffVo in buffList)
			{
				buffId = buffObj.buffid;
				if(buffId <= 0 || buffObj.isOutTime())
				{
					continue;
				}
				iconItem = getItem(buffObj);
				if(iconItem == null)
				{
					iconItem = new IconItem();
					img = new ImageContain();
					img.setSize(20,20);
					img.url = buffObj.url;
					iconItem.data = img;
					itemList.push(iconItem);
				}
				iconItem.tips = buffObj.bufferTips;
				iconItem.x = (i%10) * (20 + 2);
				iconItem.y = int(i/10)*(20 + 2)
				this.addChild(iconItem);
				i ++ ;
			}
		}
		/**
		 *获取条目 
		 * @param buff
		 * @return 
		 */		
		private function getItem(buff:BuffVo):IconItem
		{
			for each(var item :IconItem in itemList)
			{
				if(item.data && item.data.url == buff.url)
				{
					return item;
				}
			}
			return null;
		}
		/**
		 * 添加事件
		 * 
		 */		
		public function addEvtListener():void
		{
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.BUFFER_CHANFE,dataChangeHandler);
		}
		/**
		 *数据变化 
		 * @param e
		 * 
		 */	
		private function dataChangeHandler(e :Event):void
		{
			showBuffInfo();
		}
		/**
		 * 删除事件
		 * 
		 */		
		public function removeEvtListener():void
		{
		}
		/**
		 * 
		 * 销毁
		 */		
		public function destroyView():void
		{
		}
	}
}